from datetime import datetime, timedelta
from django.shortcuts import render, HttpResponse
from django.core.cache import cache
from mycelery.sms.tasks import send_sms, send_sms2
from mycelery.sms_qq.tasks import send_register_active_email


# Create your views here.

def test(request):
    # 异步任务
    # send_sms.delay('188111')
    # send_sms2.delay('122111')
    ms_code = 3222
    send_register_active_email.delay('498605991@qq.com', ms_code)
    cache.set('ms_code', ms_code, timeout=300)

    # 定时任务
    # ctime = datetime.now()
    # utc_time = datetime.utcfromtimestamp(ctime.timestamp())
    # time_delay = timedelta(seconds=6)
    # task_time = utc_time + time_delay
    # result = send_sms.apply_async(args=['19999'], eta=task_time)
    # print(result.id, '执行')

    return HttpResponse('OK')


def test2(request):
    result = cache.get('ms_code')
    print(result)
    return HttpResponse('OK')
